

package cn.gz3c.uitest.view.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView.Adapter;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;

import com.huawei.hms.audioeditor.sdk.asset.HAEAsset;
import com.huawei.hms.audioeditor.sdk.asset.HAEAudioAsset;
import com.huawei.hms.audioeditor.sdk.effect.HAEEffect;
import com.huawei.hms.audioeditor.sdk.util.SmartLog;
import com.huawei.hms.audioeditor.ui.common.listener.OnClickRepeatedListener;
import com.huawei.hms.audioeditor.ui.editor.trackview.view.d;

import java.util.Iterator;
import java.util.List;

import cn.gz3c.uitest.viewmodel.EditPreviewViewModel;
import cn.gz3c.uitest.t;
import cn.gz3c.uitest.view.NormalLineView;
import cn.gz3c.uitest.view.SpecialTrackView;
import cn.gz3c.uitest.view.TrackViewFrameLayout;
import cn.gz3c.uitest.view.WaveTrackView;

public class MainLineRecyclerViewAdapter extends Adapter<MainLineRecyclerViewAdapter.MainViewHolder> {
    private final Activity activity;
    public t b;
    private final EditPreviewViewModel editPreviewViewModel;
    private d d;

    public MainLineRecyclerViewAdapter(Activity activity, double var2, t var4, EditPreviewViewModel editPreviewViewModel) {
        this.activity = activity;
        this.b = var4;
        this.editPreviewViewModel = editPreviewViewModel;
    }

    private void a(TrackViewFrameLayout var1, List<HAEAsset> var2) {
        int var3;
        boolean var4;
        int var6;
        for (var3 = 0; var3 < var1.getChildCount(); ++var3) {
            var4 = true;
            WaveTrackView var5 = (WaveTrackView) var1.getChildAt(var3);

            for (var6 = 0; var6 < var2.size(); ++var6) {
                HAEAsset var7 = (HAEAsset) var2.get(var6);
                if (var5.a().hashCode() == var7.hashCode()) {
                    var4 = false;
                }
            }

            if (var4) {
                var1.removeView(var1.getChildAt(var3));
            }
        }

        for (var3 = 0; var3 < var2.size(); ++var3) {
            var4 = true;
            HAEAsset var8 = (HAEAsset) var2.get(var3);

            for (var6 = 0; var6 < var1.getChildCount(); ++var6) {
                if (((WaveTrackView) var1.getChildAt(var6)).a().hashCode() == var8.hashCode()) {
                    var4 = false;
                }
            }

            if (var4) {
                WaveTrackView var9;
                WaveTrackView var10001 = var9 = new WaveTrackView(this.activity, this.editPreviewViewModel);
                var9.b(var8.getUuid());
                var10001.a((HAEAudioAsset) var8);
                var1.addView(var10001);
            }
        }

    }

    private void b(TrackViewFrameLayout var1, List<HAEAsset> var2) {
        int var3 = -1;

        for (int var4 = 0; var4 < var1.getChildCount(); ++var4) {
            WaveTrackView var7 = (WaveTrackView) var1.getChildAt(var4);
            Iterator<HAEAsset> var5 = var2.iterator();

            while (true) {
                if (var5.hasNext()) {
                    HAEAsset var6 = (HAEAsset) var5.next();
                    if (!var7.o().equals(var6.getUuid())) {
                        continue;
                    }

                    var3 = -1;
                    break;
                }

                var3 = var4;
                break;
            }

            if (var3 >= 0) {
                break;
            }
        }

        var1.removeView(var1.getChildAt(var3));
        if (var2.size() > 0 && var1.getChildCount() > 0) {
            this.c(var1, var2);
        }

    }

    private void c(TrackViewFrameLayout var1, List<HAEAsset> var2) {
        for (int var4 = 0; var4 < var1.getChildCount(); ++var4) {
            HAEAudioAsset var3 = (HAEAudioAsset) var2.get(var4);
            WaveTrackView var10000 = (WaveTrackView) var1.getChildAt(var4);
            var10000.b(var3.getUuid());
            var10000.a(var3);
            var10000.r();
        }

    }

    public int getItemViewType(int var1) {
        int var2;
        if ((var2 = ((t.a) this.b.a().get(var1)).a) != 1) {
            if (var2 != 2) {
                return var2 != 6 ? -1 : 6;
            } else {
                return var1 == 0 ? 1 : 4;
            }
        } else {
            return 2;
        }
    }

    public int getItemCount() {
        return this.b.a().size();
    }

    public long getItemId(int var1) {
        return ((t.a) this.b.a().get(var1)).b != null && ((t.a) this.b.a().get(var1)).b.d != null ? (long) ((t.a) this.b.a().get(var1)).b.d.hashCode() : (long) var1;
    }

    public void a(d var1) {
        this.d = var1;
    }

    public void onBindViewHolder(@NonNull MainViewHolder var1, int var2) {
        MainLineRecyclerViewAdapter.MainViewHolder var26;
        MainLineRecyclerViewAdapter.MainViewHolder var10000 = var26 = (MainLineRecyclerViewAdapter.MainViewHolder) var1;

        IndexOutOfBoundsException var34;
        label151:
        {
            t.a var29;
            boolean var35;
            try {
                var29 = (t.a) this.b.a().get(var2);
                var35 = var10000.itemView instanceof NormalLineView;
            } catch (IndexOutOfBoundsException var25) {
                var34 = var25;
                break label151;
            }

            if (var35) {
                try {
                    ((NormalLineView) var26.itemView).a(this.b.c(), this.b.b());
                } catch (IndexOutOfBoundsException var24) {
                    var34 = var24;
                    break label151;
                }
            }

            View var27;
            try {
                var35 = (var27 = var26.itemView) instanceof TrackViewFrameLayout;
            } catch (IndexOutOfBoundsException var23) {
                var34 = var23;
                break label151;
            }

            if (!var35) {
                return;
            }

            TrackViewFrameLayout var28;
            int var36;
            int var37;
            try {
                var36 = (var28 = (TrackViewFrameLayout) var27).a();
                var37 = var29.b.c;
            } catch (IndexOutOfBoundsException var22) {
                var34 = var22;
                break label151;
            }

            if (var36 != var37) {
                try {
                    var28.removeAllViews();
                } catch (IndexOutOfBoundsException var21) {
                    var34 = var21;
                    break label151;
                }
            }

            List var3;
            int var4;
            try {
                var28.a(var29.b.c);
                var3 = var29.b.a;
                var36 = var4 = var28.b();
            } catch (IndexOutOfBoundsException var20) {
                var34 = var20;
                break label151;
            }

            if (var36 != 2) {
                if (var4 != 4) {
                    label152:
                    {
                        if (var4 != 6) {
                            return;
                        }

                        try {
                            var36 = var28.getChildCount();
                            var37 = var3.size();
                        } catch (IndexOutOfBoundsException var11) {
                            var34 = var11;
                            break label152;
                        }

                        if (var36 > var37) {
                            try {
                                this.b(var28, var3);
                            } catch (IndexOutOfBoundsException var10) {
                                var34 = var10;
                                break label152;
                            }
                        } else {
                            try {
                                var36 = var28.getChildCount();
                                var37 = var3.size();
                            } catch (IndexOutOfBoundsException var9) {
                                var34 = var9;
                                break label152;
                            }

                            if (var36 == var37) {
                                try {
                                    this.c(var28, var3);
                                } catch (IndexOutOfBoundsException var8) {
                                    var34 = var8;
                                    break label152;
                                }
                            }
                        }

                        var2 = 0;

                        while (true) {
                            try {
                                var36 = var2;
                                var37 = var3.size();
                            } catch (IndexOutOfBoundsException var7) {
                                var34 = var7;
                                break;
                            }

                            if (var36 >= var37) {
                                return;
                            }

                            try {
                                HAEAsset var32 = (HAEAsset) var3.get(var2);
                                var28.removeView(var28.getChildAt(var2));
                                WaveTrackView var5;
                                WaveTrackView var38 = var5 = new WaveTrackView(this.activity, this.editPreviewViewModel);
                                var5.b(var32.getUuid());
                                var38.a((HAEAudioAsset) var32);
                                var28.addView(var38);
                            } catch (IndexOutOfBoundsException var6) {
                                var34 = var6;
                                break;
                            }

                            ++var2;
                        }
                    }
                } else {
                    label109:
                    {
                        Iterator var30;
                        try {
                            var28.removeAllViews();
                            var30 = var29.b.b.iterator();
                        } catch (IndexOutOfBoundsException var14) {
                            var34 = var14;
                            break label109;
                        }

                        while (true) {
                            try {
                                var35 = var30.hasNext();
                            } catch (IndexOutOfBoundsException var13) {
                                var34 = var13;
                                break;
                            }

                            if (!var35) {
                                return;
                            }

                            try {
                                HAEEffect var31 = (HAEEffect) var30.next();
                                SpecialTrackView var33;
                                SpecialTrackView var39 = var33 = new SpecialTrackView(this.activity, this.editPreviewViewModel);
                                var33.b(var31.getUuid());
                                var39.b(var31);
                                var28.addView(var39);
                            } catch (IndexOutOfBoundsException var12) {
                                var34 = var12;
                                break;
                            }
                        }
                    }
                }
            } else {
                label124:
                {
                    try {
                        var36 = var28.getChildCount();
                        var37 = var3.size();
                    } catch (IndexOutOfBoundsException var19) {
                        var34 = var19;
                        break label124;
                    }

                    if (var36 > var37) {
                        try {
                            this.b(var28, var3);
                            return;
                        } catch (IndexOutOfBoundsException var15) {
                            var34 = var15;
                        }
                    } else {
                        label120:
                        {
                            try {
                                var36 = var28.getChildCount();
                                var37 = var3.size();
                            } catch (IndexOutOfBoundsException var18) {
                                var34 = var18;
                                break label120;
                            }

                            if (var36 == var37) {
                                try {
                                    this.c(var28, var3);
                                    return;
                                } catch (IndexOutOfBoundsException var16) {
                                    var34 = var16;
                                }
                            } else {
                                try {
                                    this.a(var28, var3);
                                    return;
                                } catch (IndexOutOfBoundsException var17) {
                                    var34 = var17;
                                }
                            }
                        }
                    }
                }
            }
        }

        SmartLog.d("MainLineRecyclerViewAdapter", var34.getMessage());
    }

    @NonNull
    public MainViewHolder onCreateViewHolder(@NonNull ViewGroup var1, int var2) {
        View var3;
        if (var2 != 1) {
            if (var2 != 4) {
                if (var2 != 6) {
                    var3 = new TrackViewFrameLayout(this.activity, var2, this.editPreviewViewModel, 1);
                } else {
                    var3 = new TrackViewFrameLayout(this.activity, 6, this.editPreviewViewModel, 0);
                }
            } else {
                var3 = new TrackViewFrameLayout(this.activity, 4, this.editPreviewViewModel, 0);
            }
        } else {
            var3 = new NormalLineView(this.activity, this.editPreviewViewModel);
        }

        return new MainViewHolder(var3);
    }

    static class MainViewHolder extends ViewHolder {
        public MainViewHolder(@NonNull View var2) {
            super(var2);
            var2.setOnClickListener(new OnClickRepeatedListener(v -> {

            }));
        }
    }
}
